﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using System.IO;
using System.Xml;

namespace Reborn_Server.App1AppHandler
{
    public class QuestData
    {
        public string QuestType = "";

        public long CreatureID = -1;
        public string CreatureName = "";

        public string QuestStartDialog = "";
        public string QuestFinishDialog = "";

        public bool RewardsAll = false;

        public List<Loot> CollectionItems = new List<Loot>();
        public List<Loot> RewardItems = new List<Loot>();

        public bool HasCollectionItems = false;
        public string QuestStatus = "";

        public string AssignedTo = "";

        public string toXML(Character sendingToCharacter)
        {
            string result = "";
            string innerXML = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("QuestData");

            xmldoc.WriteAttributeString("QuestType", QuestType.ToString());
            xmldoc.WriteAttributeString("QuestStatus", QuestStatus.ToString());
            xmldoc.WriteAttributeString("CreatureID", CreatureID.ToString());
            xmldoc.WriteAttributeString("CreatureName", CreatureName.ToString());
            xmldoc.WriteAttributeString("HasCollectionItems", HasCollectionItems.ToString());
            xmldoc.WriteAttributeString("RewardsAll", RewardsAll.ToString());
            xmldoc.WriteAttributeString("AssignedTo", AssignedTo.ToString());

            xmldoc.WriteStartElement("RewardItems");
            innerXML = "";
            foreach (Loot loot in RewardItems)
            {
                innerXML = innerXML + loot.toXML(sendingToCharacter);
            }
            if (innerXML != "") xmldoc.WriteRaw(innerXML);
            xmldoc.WriteEndElement();

            xmldoc.WriteStartElement("QuestStartDialog");
            xmldoc.WriteString(QuestStartDialog);
            xmldoc.WriteEndElement();

            xmldoc.WriteStartElement("QuestFinishDialog");
            xmldoc.WriteString(QuestFinishDialog);
            xmldoc.WriteEndElement();

            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }
}
